package com.ml.mall.mapper.company;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.req.company.CompanyQueryDto;
import com.ml.mall.bean.res.company.CompanyInfoRes;
import com.ml.mall.bean.res.company.CompanyQueryRes;
import com.ml.mall.bean.res.dashboard.DashboardCompanyRes;
import com.ml.mall.bean.vo.sys.SysUserCompanyRelationVo;
import com.ml.mall.entity.company.SysCompany;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface SysCompanyMapper extends BaseMapper<SysCompany> {

    //更新可配送周
    @Update("update sys_company set states_can_send = #{statesCanSend} where company_id = #{companyId} ")
    int updateStatesArrByCompanyId(@Param("companyId") Long companyId,@Param("statesCanSend") String statesCanSend);

    List<CompanyInfoRes> selectCompanyInfoBatch(@Param("companyList") List<Long> companyList);
    //根据类型查询全部的公司
    CompanyQueryRes selectAllCompanyByType(@Param("companyType") Integer companyType);

    //取消卖家与合作商之间的关联；更新卖家
    @Update("update sys_company set registartion_no = null  where id = #{id}")
    int updateRegister(@Param("id") Long id);

    @Select("select count(id) from sys_company where invite_code = #{inviteCode}")
    int selectCountByInviteCode(@Param("inviteCode") String inviteCode);

    /**
     * @description    :公司信息分页查询
     * @author         :zxm
     * @date           :2021/5/14
    **/
    List<CompanyQueryRes> selectPageCompany(@Param("dto") CompanyQueryDto dto);

    /**
     * @description    :统计分页信息总数
     * @author         :zxm
     * @date           :2021/5/14
    **/
    Long countCompany(@Param("dto")CompanyQueryDto dto);

    /**
     * @description    :通过公司自定义id查询公司信息
     * @author         :zxm
     * @date           :2021/5/25
    **/
    SysCompany selectByCompanyId(@Param("companyId") Long companyId);

    /**
     * @description    :汇总供应商和采购商公司数量
     * @author         :zxm
     * @date           :2021/5/25
    **/
    DashboardCompanyRes sumTotalCompany();

    /**
     * 通过邀请码创建账户中用于查找company_type
     * @param companyId
     * @return
     */
    @Select("select company_type from sys_company where company_id = #{companyId}")
    String selectInviteDataByCompanyId(@Param("companyId") Long companyId);

    /**
     * 查找sys_company中的companyName
     * @param companyId
     * @return
     */
    @Select("select company_name from sys_company where company_id = #{companyId}")
    String selectCompanyNameByCompanyId(@Param("companyId") Long companyId);

    @Select("select count(variant_id) from sys_product_variant where is_delete = 0 and supplier_id = #{companyId}")
    Long querySupplierVariantNum(@Param("companyId") Long companyId);

    /**
     * 查询供应商的产品数
     * @param companyId
     * @return
     */
    Long countSupplierProduct(Long companyId);

    @Update("update sys_company set is_paid = 1 where company_id = #{companyId}")
    Integer updateCompanyIsPaid(@Param("companyId")Long companyId);

    int updateByEmail(@Param("emailAddress") String emailAddress);

    SysCompany selectByEmail(String emailAddress);
}
